/* 
 * Copyright (C) 2013, 2014 lex
 *
 * file:	net/net.h
 * history:	2013 Sep 11 created by lex
 * comment:
 */

#ifndef __NET_H__
#define __NET_H__

#define ETH_ALEN	6		/* Octets in one ethernet addr	 */
#define ETH_HLEN	14		/* Total octets in header.	 */
#define ETH_ZLEN	60		/* Min. octets in frame sans FCS */
#define ETH_DATA_LEN	1500		/* Max. octets in payload	 */
#define ETH_FRAME_LEN	1514		/* Max. octets in frame sans FCS */
#define ETH_FCS_LEN	4		/* Octets in the FCS		 */

struct eth_hdr {
	u8	dst[ETH_ALEN];
	u8	src[ETH_ALEN];
	u16	type;
} __attribute__ ((packed));


enum {
	PROTOCOL_ARP,
	PROTOCOL_ICMP,
	PROTOCOL_TFTP,
	PROTOCOL_BOOTP,
	PROTOCOL_DHCP,
};

struct nt_ctrl_buf {
	struct list_head link;

	union {
		struct {
			struct eth_hdr *eh;

			union {
				struct arp_hdr *ah;
				struct ip_hdr  *ih;
			};

			union {
				struct icmp_hdr *icmp_hdr;
				struct tcp_hdr  *tcp_hdr;
				struct udp_hdr  *udp_hdr;
			};
		};

		u32	data[6];
	} h;

	u16	protocol;
	u16	data_len;

	u8	state;

	void	(*curr_handler)(struct ne_ctrl_buf *);
	void	(*next_handler)(struct ne_ctrl_buf *);
	void	(*timeout)(struct ne_ctrl_buf *);

	u8	*head;		/* Header of buffer  */
	u8	*data;		/* Data head pointer */
	u8	*tail;		/* Data tail pointer */
	u8	*end;		/* End of buffer     */
};

//struct 

#endif	/* end of __NET_H__ */
